<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css.css">
</head>
<body>
<h2>
    <span id="h">00</span>
    :
    <span id="f">00</span>
    :
    <span id="s">00</span>
</h2>
<script>
    //倒计时
    //结束时间
    var jieshu = new Date('2019-09-06 15:50:00');

    //设置当前时分秒
    var h = 0;
    var f = 0;
    var s = 0;
    function daojishi() {
        //获取现在时间
        var xianzai = new Date();
        //获取相差的时分秒
        var xiangcha = jieshu.getTime() - xianzai.getTime();
        console.log(xiangcha);
        //相差的秒数
        xiangcha = xiangcha / 1000;
        console.log(xiangcha);
        xiangcha = parseInt(xiangcha);
        if (xiangcha >= 0) {
            //根据多余秒数算出剩余小时
            h = parseInt(xiangcha / 3600);
            //根据多余秒数算出剩余分钟
            f = parseInt((xiangcha / 60) % 60);
            //根据多余秒数算出剩余秒数
            s = parseInt(xiangcha % 60);

            //利用两位数表示剩余时间   如果小于10，就在前面加上一个0

            if (h < 10) {
                h = '0' + h
            }
            if (f < 10) {
                f = '0' + f
            }
            if (s < 10) {
                s = '0' + s
            }
        } else {
            console.log('倒计时结束');
            clearInterval(t);
        }
        //给相应的地方加上相应的东西
        document.querySelector("#h").innerHTML = h;
        document.querySelector("#f").innerHTML = f;
        document.querySelector("#s").innerHTML = s;
    }
    //先预先执行一遍代码
    daojishi();
    //计时器一直执行
    var t = setInterval(function () {
        daojishi();
    }, 1000);
    </script>
<script src="script.js"></script>
</body>
</html>